package com.xdjd.task.service.daoservice;


import com.xdjd.task.mapper.activity.ActivityChallengeRecordPoDao;
import com.xdjd.task.model.activity.ActivityChallengeRecordPo;
import com.xdjd.task.util.DateUtil;
import net.oschina.durcframework.easymybatis.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2019/1/9 0009.
 */
@Service
public class ActivityChallengeRecordPoService {

    @Autowired
    private ActivityChallengeRecordPoDao activityChallengeRecordPoDao;

    public ActivityChallengeRecordPo findTodayRecordByMemberId(Long memberId) {
        Query query = new Query().eq("member_id", memberId).eq("record_date", DateUtil.getDate(new Date()));
        return activityChallengeRecordPoDao.getByExpression(query);
    }

    public void saveRecord(ActivityChallengeRecordPo po) {
        po.setCreateTime(new Date());
        po.setModifyTime(new Date());
        activityChallengeRecordPoDao.save(po);
    }

    public void updateTodayStepByMemberId(Long memberId, Long stepNumber) {
        activityChallengeRecordPoDao.updateTodayStepByMemberId(memberId, stepNumber);
    }

    public void settleChallenge() {
        activityChallengeRecordPoDao.settleChallenge();
    }

    public List<ActivityChallengeRecordPo> findTodayRecord() {
        Query query = new Query().gt("challenge_count", 0).eq("record_date", DateUtil.getDate(new Date()));
        return activityChallengeRecordPoDao.findAll(query);
    }

    public void updateRecord(ActivityChallengeRecordPo po) {
        po.setModifyTime(new Date());
        activityChallengeRecordPoDao.update(po);
    }
}
